﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Umbraco.Framework.Persistence.Model;
using Umbraco.Hive.ProviderGrouping;
using Umbraco.Hive.Providers.WordPress.Schema.Model;
using Umbraco.Hive.Providers.WordPress.Schema.Model.AttributeDefinitions;

namespace Umbraco.Hive.Providers.WordPress.Entity
{
    public static class RepositoryExtensions
    {
        public static IEnumerable<TypedEntity> GetPostsByAuthor(this IReadonlyEntityRepositoryGroup<IWordPressStore> session, string authorName)
        {
            return session.GetAll<TypedEntity>()
                .Where(x => x.EntitySchema.Alias == PostSchema.SchemaAlias && x.Attributes[AuthorAttributeDefinition.AliasValue].DynamicValue == authorName);
        }
    }
}
